package cn.wolfcode.business.task;

import cn.wolfcode.business.domain.BusAppointment;
import cn.wolfcode.business.mapper.BusAppointmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("appointmentTask")
public class AppointmentTask {
    @Autowired
    private BusAppointmentMapper appointmentMapper;

    /**
     * 预约超时取消
     */
    public void AppointmentOvertime() {
        List<Integer> status = new ArrayList<>();
        status.add(BusAppointment.STATUS_APPOINTMENT);

        List<BusAppointment> list = appointmentMapper.selectByStatus(status, BusAppointment.IS_DEL);

        for (BusAppointment busAppointment : list) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(busAppointment.getAppointmentTime());
            calendar.add(Calendar.HOUR_OF_DAY, 6);
            Date overTime = calendar.getTime();

            if (overTime.before(new Date())) {
                appointmentMapper.updateStatus(busAppointment.getId(), BusAppointment.STATUS_OVERTIME);
//                System.out.println(busAppointment.getCustomerName() + "已超时");
            }
        }
    }
}
